import random

number=12

def random_captcha_text(char_set=number, captcha_size=4):  # 可以设置只用来生成数字
    captcha_text = []
    for i in range(captcha_size):
        c = random.choice(char_set)
        captcha_text.append(c)
    return captcha_text


def gen_capthcha_text_and_image(m):
    image = ImageCaptcha()
    captcha_text = random_captcha_text()  # 生成数字
    captcha_text = ' '.join(captcha_text)  # 生成标签

    image.write(captcha_text, "./data/image/" + '%.4d' % m + '.jpg')  # 保存图片

    # 将标签信息写入
    with open(data_path + "label.txt", "a") as f:
        f.write(captcha_text)
        f.writelines("\n")

if __name__ == '__main__':
    print(random_captcha_text(12,3))